package com.dhms.vostok1.adapter

import android.widget.ImageView
import androidx.core.net.toUri
import androidx.databinding.BindingAdapter
import coil.load
import com.dhms.mine.R
import com.dhms.vostok1.data.LocalUserInfoData

@BindingAdapter("avatar")
fun bindUserAvatar(imgView: ImageView, userInfoData: LocalUserInfoData?) {
    val userAvatarUrl = userInfoData?.avatar
    userAvatarUrl?.let {
        val imgUri = userAvatarUrl.toUri().buildUpon().scheme("https").build()
        imgView.load(imgUri) {
            placeholder(R.drawable.ic_avatar_placeholder)
            error(R.drawable.ic_avatar_placeholder)
        }
    }
}